home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 902 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.3 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: "explicit" default constructor?
  5. Date: 28 Mar 1996 20:27:21 GMT
  6. Organization: Technical University of Berlin
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <315AF30F.4855@cs.tu-berlin.de>
  9. References: <315A5C7A.6AF5@cs.tu-berlin.de> <4jeds0$h0b@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="us-ascii"
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: 130.149.17.235
  15. X-Mailer: Mozilla 2.0 (Win95; I)
  16. X-Lines: 61
  17. Content-Length: 2294
  18. Originator: clamage@taumet
  19.  
  20. Steve Clamage wrote:
  21. > In article 6AF5@cs.tu-berlin.de, Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
  22. > >Steve Clamage wrote:
  23. > >
  24. > >> A converting constructor is one which can be called with a single parameter.
  25. > >> The default constructor isn't a converting constructor except in the
  26. > >> case of a constructor with all parameters having default values.
  27. > >>
  28. > >> If a constructor has no parameters, declaring it "explicit" has no effect,
  29. > >> since it can never be invoked for a conversion.
  30. > >
  31. > >> If a constructor's parameters all have default values, it can be a
  32. > >> converting constructor, and declaring it "explicit" prevents it from
  33. > >> being invoked implicitly.
  34. > >
  35. > >Yes, I've had this in mind, too. In the following case:
  36. > >
  37. > >class A
  38. > >{
  39. > > explicit A( int x=0 );
  40. > >};
  41. > >
  42. > >how do you call the default constructor?
  43. > The same way you always did before. The default constructor is one which
  44. > requires no parameters. If implicitly or explicitly invoked with no
  45. > parameters, no conversion is taking place, and it is a non-converting
  46. > constructor.
  47.  
  48. Sorry for posting another article on this topic ( I wasn't going to, honest ) 
  49. but I'm really not happy with this section of the DWP ( you might remember 
  50. the thread about copy constructors ). However, you agree that a default 
  51. constructor is a non-converting constructor. Then I read this passage in the 
  52. DWP:
  53.  
  54.   A  nonconverting  constructor  constructs objects just like converting
  55.   constructors, but does so only where a constructor call is  explicitly
  56.   indicated by the syntax. [class.conv.ctor]
  57.  
  58. Do you see how this can be interpreted? A default constructor is 
  59. non-converting, so it constructs objects only if its call is "explicitly 
  60. indicated". The DWP doesn't say that this section deals only with 
  61. constructors that could be converting or are invoked for a conversion. BTW, 
  62. I'm talking only about the definitions in the DWP, not about the language 
  63. itself (i.e. I'm not confused how to call default constructors). So, if we 
  64. argue strictly on the basis of the DWP, where am I wrong?
  65.  
  66. > > An explicit call would rather be
  67. > >
  68. > >A a();
  69. > No, that declares 'a' to be a function with no parameters returning an
  70. > 'A' by value.
  71.  
  72. Oops. Sure. Sorry. Probably I should get some sleep.
  73.  
  74. Bye
  75.  
  76. Roman
  77.  
  78.  
  79. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  80. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  81. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  82. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  83. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  84.